package com.scalar.chiptrack.operations.dataentry.actionCommands;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.dataentry.DataEntryHelper;
import com.scalar.chiptrack.operations.dataentry.forms.DieBankBinningInfoForm;
import com.scalar.chiptrack.operations.process.dao.LotDAO;

/**
 * User: Murali Krishna Yengala
 * Date: Jul 22, 2005
 * Time: 5:47:23 PM
 */
public class DieBankBinningInfoLoadLocationsCommand extends ChipTrackExtendedAction{
    public ActionForward executeRequest( ActionMapping mapping,
                                         ActionForm form,
                                         HttpServletRequest request,
                                         HttpServletResponse response) throws Exception
    {
        HashMap errors              = ( HashMap ) request.getAttribute( ERROR_MESSAGES );
        HashMap info                = ( HashMap ) request.getAttribute( INFO_MESSAGES );
        String forward = "dieBankBinningInfoEntry";
        DieBankBinningInfoForm dieBankBinningInfoForm = (DieBankBinningInfoForm) form;
        try
        {
            int processStepId = Integer.parseInt( dieBankBinningInfoForm.getProcessStepId() );
            DataEntryHelper.loadSortPartNumbers( request);
            DataEntryHelper.loadLocations( processStepId, request);
            dieBankBinningInfoForm.setWafers( null);
            dieBankBinningInfoForm.setGrossDie(LotDAO.getFabGrossDieFromProcessStepId( null, processStepId ) );
        }
        catch( Exception e)
        {
            e.printStackTrace();
            errors.put(ERROR_INTERNAL_SERVER_ERROR, "Could not load Locations");
            DataEntryHelper.loadSortPartNumbers( request);
            DataEntryHelper.resetForm( dieBankBinningInfoForm);
        }

        request.setAttribute (SessionKeys.INFO_MESSAGES, info);
        request.setAttribute (SessionKeys.ERROR_MESSAGES, errors);
        return mapping.findForward( forward );
    }
}
